import 'package:jvtd_flutter_utils/src/date/date_util.dart';

extension DateTimeExtension on DateTime {
  /// 是否为同一天
  ///
  /// [date] 匹配判断的时间
  bool isSameDay({DateTime date}) {
    date = date ?? DateTime.now();
    return this.year == date.year && this.month == date.month && this.day == date.day;
  }

  /// 是否为闰年
  bool isLeapYear() {
    return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
  }

  /// 是否为同一年
  bool isSameYear({DateTime date}) {
    date = date ?? DateTime.now();
    return year == date.year;
  }

  /// 获取当前时间的时间区间
  ///
  /// [intervalType] 时间区间类型
  List<DateTime> interval({DateIntervalType intervalType = DateIntervalType.day}) {
    return DateUtil.interval(this, intervalType: intervalType);
  }
}
